package gamagora.game.entity
{
	import gamagora.game.resources.OSImages;
	
	import org.flixel.FlxG;

	public class OSSari extends OSEntity
	{
		private static const INTERVAL:Number = 100.0
		
		private var _xSpeed:Number;
		private var _ySpeed:Number;
		private var _moving:Boolean;
		private var _goUp:Boolean;
		
		public function OSSari(X:Number=0, Y:Number=0, framerate:uint = 20, xSPeed:Number = 200, ySpeed:Number = 100)
		{
			super(NOTHING, X, Y);
			_xSpeed = xSPeed;
			_ySpeed = ySpeed;
			loadGraphic(OSImages.SARI, true, false, 128, 128);
			_moving = framerate > 0;
			if(_moving)
			{
				addAnimation("sari", [0, 1, 2, 3, 4, 5, 6, 7], framerate, true);
				play("sari");
			}
			_goUp = true;
			offset.x = 32;
			offset.y = 20;
		}
		
		public override function update():void
		{
			super.update();
			
			if(_moving)
			{
				if(_goUp)
				{
					y -= FlxG.elapsed * _ySpeed;
					if(y <= _startY - INTERVAL)
					{
						_goUp = false;
					}
				}
				else
				{
					y += FlxG.elapsed * _ySpeed;
					if(y >= _startY + INTERVAL)
					{
						_goUp = true;
					}
				}
				
				x += FlxG.elapsed * _xSpeed;
			}
		}

		public function get moving():Boolean
		{
			return _moving;
		}

		public function set moving(value:Boolean):void
		{
			_moving = value;
		}

	}
}
